package com.think.teaching.mapper;

import com.think.teaching.model.Major;
import com.think.teaching.model.StudentInfo;

import java.util.Map;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * <p>
 * 学生详细信息 Mapper 接口
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
public interface StudentInfoMapper extends BaseMapper<StudentInfo> {

	@Select("<script>SELECT * FROM student_info WHERE delflag=0 "
			+ "<if test='state gt 0'>AND state=#{state}</if>"
			+ "AND class_id IN (SELECT class.id FROM class,major,college,school WHERE class.major=major.id AND college.id=major.college AND school.id=college.school"
			+ "<if test='classId gt 0'>AND class.id=#{classId}</if>"
			+ "<if test='major gt 0'>AND major.id=#{major}</if>"
			+ "<if test='college gt 0'>AND college.id=#{college}</if>"
			+ "<if test='school gt 0'>AND school.id=#{school}</if>)"
			+ "ORDER BY student_info.created_time DESC</script>")
	@Result(column = "class_id",property = "class",jdbcType = JdbcType.JAVA_OBJECT,javaType = Major.class,one = @One(select = "com.think.teaching.mapper.ClassMapper.getClassDetailes",fetchType = FetchType.EAGER))
	IPage<Map<String, Object>> listStudentInfo(IPage<Map<String, Object>> page,
											  @Param("state") Integer state,
											   @Param("classId") Integer classId,
											   @Param("major") 	Integer major,
											   @Param("college")  Integer college,
											   @Param("school") Integer school);
	
	@Select("<script>SELECT * FROM student_info WHERE delflag=0 AND user_id=#{id}"
			+ "</script>")
	@Result(column = "class",property = "class",jdbcType = JdbcType.JAVA_OBJECT,javaType = Major.class,one = @One(select = "com.think.teaching.mapper.ClassMapper.getClassDetailes",fetchType = FetchType.EAGER))
	Map<String,Object> getStudentInfoByUserId(Integer userId);
}
